package com.example.administrator.x3picturetransliteration.Home.Presenter.Activity;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.example.administrator.x3picturetransliteration.Base.BasePresenter;
import com.example.administrator.x3picturetransliteration.Base.HttpGo;
import com.example.administrator.x3picturetransliteration.Bean.HttpDataBean;
import com.example.administrator.x3picturetransliteration.Bean.ReplyBean;
import com.example.administrator.x3picturetransliteration.Bean.feedbackListBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import rx.subscriptions.CompositeSubscription;

/**
 * 反馈记录
 * Created by Administrator on 2019/9/12.
 */

public class FeedbackRecordPresenter extends BasePresenter{

    public FeedbackRecordPresenter(Context context, CompositeSubscription mCompositeSubscription) {
        super(context, mCompositeSubscription);
    }

    /** 反馈列表 */
    private Integer feedbackListPageNum = 1;
    public void feedbackList(boolean Refresh, final Callback mCallback){

        if (Refresh)feedbackListPageNum = 1;

        Map<String,String> httpdata = new HashMap<>();

        httpdata.put("page",feedbackListPageNum + "");
        httpdata.put("limit","10");

        mCompositeSubscription.add(

                mHttpGo.postSubscription("user_feedback/list", httpdata,null, new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0){

                            if (httpDataBean.getData()!=null){

                                List<feedbackListBean> listdata = JSON.parseArray(httpDataBean.getData() + "", feedbackListBean.class);

                                if (listdata.size()>0)feedbackListPageNum = feedbackListPageNum + 1;

                                mCallback.getData(listdata);
                            }
                        }
                    }
                })
        );
    }

    /** 解决详情 */
    public void reply(String id, final Callback mCallback){

        Map<String,String> httpdata = new HashMap<>();
        httpdata.put("id",id);

        mCompositeSubscription.add(

                mHttpGo.postSubscription("user_feedback/reply", httpdata,null, new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0){

                            if (httpDataBean.getData()!=null){


                                mCallback.getData(JSON.parseObject(httpDataBean.getData() + "", new TypeReference<ReplyBean>() {}));
                            }
                        }
                    }
                })
        );
    }

}
